<?php

namespace App\Console\Commands;

use App\Helpers\Logger\SLogger;
use App\Models\Orm\User;
use App\Models\Factory\UserFactory;
use Illuminate\Console\Command;
use DB;

class VipExpiration extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'VipExpiration';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '更新已过期的vip用户';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        /**
        * 将过期的vip用户更新vip等级
        */
        set_time_limit(0);
        
        $vipUser = UserFactory::allVipUser();
        foreach ($vipUser as $key => $value) {
            if($value['vip_expiration'] <= date('Y-m-d H:i:s', time())){
                User::where(['id' => $value['id']])->update(['vip_level'=>0]);                
            }
        }   

    }



}
